package test.freshui.ffmpeg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class PlayerUI extends Activity {
	static private final String TAG = "PlayerUI";
	private PlayerView mPlayerView = null;
	private PlayerControl mPlayerControl = null;
	public static int mWidth, mHeight; 
    /** Called when the activity is first created. */
	
	static {
		try{
			System.loadLibrary("ffmpeg");
			System.loadLibrary("ffmpeg-jni");
		} catch (Exception e){
			Log.e("test", "error:"+e);
			e.printStackTrace();
		}
	};
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  
		/* Request fullscreen window */	   
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		   					WindowManager.LayoutParams.FLAG_FULLSCREEN);

		
        //setContentView(R.layout.main);
        setContentView(R.layout.main_froyo);
        
        mPlayerView = (PlayerView)findViewById(R.id.videoView);
    }
    
    /* focus changed! mean layout finished! */
    @Override
    public void onWindowFocusChanged(boolean hasFocus){
        if(mPlayerView != null){
    		Log.d(TAG, "mVideoView, width="+mPlayerView.getWidth()+", height="+mPlayerView.getHeight());
    		mPlayerView.init(mPlayerView.getWidth(), mPlayerView.getHeight());
        }
        mPlayerControl = new PlayerControl(mPlayerView);
        
        Intent intent = getIntent();
        Bundle bundle  = intent.getExtras();
        String path = bundle.getString("file_path");
        Log.d("test", "path"+path);
        
        mPlayerControl.startPlay(path);
        mPlayerControl.start();
    }
    
    @Override
	public void onPause(){
    	mPlayerControl.stop();
    }

    @Override
	public void onStop(){
    	mPlayerControl.cleanup();
    }
}


